package com.example.userbehaviorprediction;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.content.Intent;
import android.widget.Switch;
import android.widget.Toast;

public class main_func extends AppCompatActivity {

    Button btn;

    Switch swi;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        overridePendingTransition(R.anim.activity_slide_in_right, R.anim.activity_slide_out_left);

        setContentView(R.layout.activity_mainfunc);

        btn=findViewById(R.id.button1);
        swi=findViewById(R.id.switch3);
        Intent intent2=new Intent(main_func.this,ReadDataService.class);

        swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if(isChecked){
                    Toast.makeText(main_func.this,"授权成功，Service已启动！",Toast.LENGTH_SHORT).show();
                    startService(intent2);
                    btn.setEnabled(true);

                }else{
                    stopService(intent2);
                    btn.setEnabled(false);
                    Toast.makeText(main_func.this,"关闭授权，Service关闭啦。",Toast.LENGTH_SHORT).show();

                }
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View arg0) {


                Intent intent=new Intent(main_func.this,show.class);

                startActivity(intent);

            }

        });





    }

//    @Override
//    public void finish() {
//        super.finish();
//        overridePendingTransition(R.anim.activity_slide_in_left, R.anim.activity_slide_out_right);
//    }

}
